<?php
class cartoon_controller_collect extends SnsController {
	public function __construct($app, $controller){
		parent::__construct($app, $controller);
		$this->o = new cartoon_model_collect();
	}
	
	/**
	 * 添加收藏
	 *
	 */
	public function add_action(){
		$this->requireLogin();
		$args['uid'] = self::$login['uid'];
		$args['cartoon_id']	=	_('ctid');
		$args['chapter_id']	=	_('cid');
		if($args['chapter_id']){
			$args['url']	=	'http://www.'.DOMAIN.self::_makeURL('cartoon','index','view_photo',array('ctid'=>$args['cartoon_id'],'cid'=>$args['chapter_id']));
		}else{
			$args['url']	=	'http://www.'.DOMAIN.self::_makeURL('cartoon','index','view',array('cid'=>$args['cartoon_id']));
		}
		$args['add_time']	=	CURRENT_TIME;
		$this->_renderJson();
		if($rs = $this->o->add($args)){
			if($rs == ERR_EXISTS){
				$this->ret = self::failure('您已经过收藏过了！');
			}
			else $this->ret = self::success();
		}else{
			$this->ret = self::failure("添加收藏失败！");
		}
	}
	
	/**
	 * 删除收藏
	 *
	 */
	public function remove_action(){
		$this->requireLogin();
		$uid = self::$login['uid'];
		$id	=	_('id');
		$this->_renderJson();
		if($this->o->remove($id)){
			$this->ret = self::success();
		}else{
			$this->ret = self::failure("删除收藏失败！");
		}
	}
	
}